function ret=circshift(A,p)//m1,m2)
[m,n]=size(A);
//rettmp=zeros(m,n);
idxr=zeros(1,m);
//idxc=zeros(1,n);
//ret=zeros(m,n);
//for i=1:m
//    id=pmodulo(i-m1-1,m)+1;
//    rettmp(i,:)=A(id,:);
//end
//for j=1:n
//    jd=pmodulo(j-m2-1,n)+1;
//    ret(:,j)=rettmp(:,jd);
//end
//for i=1:m
//    //    id=pmodulo(i-m1-1,m)+1;
//    id=pmodulo(i-p-1,m)+1;
//    idxr(i)=id;
//end
p = modulo(p,m);
if p > 0 then
    idxr = [(m-p+1):m, 1:(m-p)];
elseif p <= 0 then
    idxr = [(1-p):m, 1:-p];
end
ret = A(idxr,:);
//rettmp = A(idxr,:);
//for j=1:n
//    jd=pmodulo(j-m2-1,n)+1;
//    idxc(j)=jd;
//end
//ret=rettmp(:,idxc);
endfunction
